﻿Ext.define('Admin.view.process.definition.ProcessDefinitionGrid', {
    extend: 'Ext.grid.Panel',
    xtype: 'process-definition-grid',
    id: 'process-definition-grid',
    title: '流程部署',
    iconCls: 'x-fa fa-arrow-circle-o-up',
    // requires: ['Ext.grid.Panel',
    // 'Ext.toolbar.Paging','Ext.grid.column.Date'],//加载插件,只加载1次
    controller: 'processdefinition', // 视图控制器
    // cls: 'user-grid',
    viewModel: {
        type: 'process-definition-viewmodel'
    }, // 视图数据模型

    bind: '{processDefinitionGridStore}', // store //视图数据仓库(源)
    // scrollable: false,
    columns: [{
            header: '流程定义实体Id',
            dataIndex: 'id',
            width: 120,
            sortable: true
        },
        {
            header: '类别',
            dataIndex: 'category',
            width: 200,
            sortable: true
        },
        {
            header: '名称',
            dataIndex: 'name',
            width: 100,
            sortable: true
        },
        {
            header: '流程key',
            dataIndex: 'key',
            width: 80,
            sortable: true
        },
        {
            header: '版本号',
            dataIndex: 'version',
            width: 60,
            sortable: true
        },
        {
            header: '部署Id',
            dataIndex: 'deploymentId',
            width: 60,
            sortable: true,
            hidden: true
        },
        {
            header: '部署时间',
            dataIndex: 'deploymentTime',
            width: 150,
            sortable: true,
            renderer: Ext.util.Format.dateRenderer('Y/m/d H:i:s')
        },


        {
            header: 'bpmn XML',
            dataIndex: 'resourceName',
            width: 120,
            sortable: true,
            renderer: function(value, metaData, record, rowIdx, colIdx,
                store, view) {
                return '<a target="_blank" href="' +
                    'processdefinition/resource?pdid=' +
                    record.get('id') + '&resourceName=' +
                    record.get('resourceName') + '">' +
                    record.get('resourceName') + '</a>';
            },
            hidden: true
        },
        {
            header: '图片',
            dataIndex: 'diagramResourceName',
            width: 120,
            sortable: true,
            renderer: function(value, metaData, record, rowIdx, colIdx,
                store, view) {
                return '<a target="_blank" href="' +
                    'processdefinition/resource?pdid=' +
                    record.get('id') + '&resourceName=' +
                    record.get('diagramResourceName') + '">' +
                    record.get('diagramResourceName') + '</a>';
            },
            hidden: true
        }

        , {
            header: '是否挂起',
            dataIndex: 'suspended',
            width: 80,
            sortable: true,
            hidden: true
        }

        , {
            header: 'startFormKey',
            dataIndex: 'startFormKey',
            width: 180,
            sortable: true,
            hidden: true
        }, {
            header: 'graphicalNotation',
            dataIndex: 'graphicalNotation',
            width: 180,
            sortable: true,
            hidden: true
        }, {
            header: 'description',
            dataIndex: 'description',
            width: 60,
            sortable: true,
            hidden: true
        }, {
            header: 'tenantId',
            dataIndex: 'tenantId',
            width: 180,
            sortable: true,
            hidden: true
        }, {
            xtype: 'actioncolumn',
            items: [{
                    xtype: 'button',
                    iconCls: 'x-fa fa-trash-o',
                    tooltip: '删除',
                    handler: 'onClickProcessDefinitionGridDeleteButton'
                }, {
                    xtype: 'button',
                    iconCls: 'x-fa  fa-file-excel-o',
                    tooltip: 'BPMN XML',
                    handler: 'onClickProcessDefinitionReadResourceButton'
                }, {
                    xtype: 'button',
                    iconCls: 'x-fa fa-file-picture-o',
                    tooltip: '流程定义图',
                    handler: 'onClickProcessDefinitionReadDiagramResourceButton'
                }, {
                    xtype: 'button',
                    iconCls: 'x-fa fa-cog',
                    getClass: function(v, meta, rec) {
                        if (rec.get('suspended') != true) {
                            return 'x-hidden';
                        }
                        return 'x-fa fa-cog';
                    },
                    tooltip: '激活',
                    handler: 'onClickProcessDefinitionActiveButton'
                },
                {
                    xtype: 'button',
                    iconCls: 'x-fa fa-ban',
                    getClass: function(v, meta, rec) {
                        if (rec.get('suspended') != false) {
                            return 'x-hidden';
                        }
                        return 'x-fa fa-ban';
                    },
                    tooltip: '挂起',
                    handler: 'onClickProcessDefinitionSuspendButton'
                }, {
                    xtype: 'button',
                    iconCls: 'x-fa fa-exchange',
                    tooltip: '转换为Model',
                    handler: 'onClickProcessDefinitionGridConvertModelButton'
                }
            ],
            cls: 'content-column',
            width: 260,
            dataIndex: 'bool',
            text: '操作'
        }
    ],
    dockedItems: [{
        // itemId: process-definition-gridToolbar',//注意id冲突
        xtype: 'pagingtoolbar',
        dock: 'bottom',
        bind: '{processDefinitionGridStore}', // store //视图分页数据仓库(源)
        displayInfo: true,
        items: ['-', {
            text: '上传',
            iconCls: 'x-fa fa-arrow-up',
            listeners: {
                click: 'onClickProcessDefinitionGridUploadButton'
            }
        }]
    }]
});